package common.fengkai.filepost.test;

import common.fengkai.filepost.bean.mysqlBean.EmpUser;
import org.aspectj.weaver.ast.Var;

import java.sql.SQLOutput;
import java.util.*;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;

/**
 * @author Fengkai
 * @creat 2023/5/15
 * 题目二：存在重复元素
 * 给你一个整数数组 nums 。如果任一值在数组中出现 至少两次 ，返回 true ；如果数组中每个元素互不相同，返回 false 。
 * 示例 1：
 * 输入：nums = [1,2,3,1]
 * 输出：true
 * 示例 2：
 * 输入：nums = [1,2,3,4]
 * 输出：false
 * <p>
 * 输入：nums = [1,1,1,3,3,4,3,2,4,2]
 * 输出：true
 */
public class Demo {

    public static void main (String[] args) throws ExecutionException, InterruptedException {

        FutureTask<EmpUser> stringFutureTask = new FutureTask<>(new Callable<EmpUser>() {
            @Override
            public EmpUser call () throws Exception {
                try {
                    Thread.sleep(100);
                    EmpUser empUser = new EmpUser();
                    empUser.setName("test").setAge(18).setSex("1").setDr("male");
                    return empUser;
                } catch (Exception e) {
                    return null;
                }
            }
        });

        Thread thread = new Thread(stringFutureTask);
        thread.start();

        Scanner scanner = new Scanner(System.in);
        String s = scanner.nextLine();
        String[] split = s.split(",");

        System.out.println(get(split));

        EmpUser empUser = stringFutureTask.get();
        if (empUser != null){
            System.out.println(empUser);
        }



    }

    public static boolean get (String[] input) {
        HashSet<String> strings = new HashSet<String>();
        for (String s1 : input) {
            boolean add = strings.add(s1);
            if (!add) {
                return true;
            }
        }
        return false;
    }

}
